import { Controller, Post, Get, Put, Body, Param } from '@nestjs/common';
import { AddressService } from './address.service';
import { Address } from '../entities/address.entity';

@Controller('address')
export class AddressController {
  constructor(private readonly addressService: AddressService) {}

  @Post()
  async createAddress(@Body() addressData: Partial<Address>): Promise<Address> {
    return await this.addressService.createAddress(addressData);
  }

  @Get(':phone')
  async getAddressByPhone(@Param('phone') phone: string): Promise<Address[]> {
    return await this.addressService.getAddressByPhone(phone);
  }

  @Put(':id')
  async updateAddress(
    @Param('id') id: number,
    @Body() addressData: Partial<Address>,
  ): Promise<Address> {
    return await this.addressService.updateAddress(id, addressData);
  }
}
